package com.stepshop.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;

/**
 * 正则表达式工具类
 * 可查看jdk api java.util.regex 
 */
public class RegexUtils {
	private static Logger logger=Logger.getLogger(RegexUtils.class);
	private RegexUtils(){
		
	}
	/**
	 * 校验手机号是否符合规则
	 */
	public static boolean judgePhoneNumber(String phoneNumber){
		String regex = "^[1][3578][0-9]{9}$";
		return judgeMethod(regex, phoneNumber);
	}
	/**
	 * 校验邮箱是否满足规则 
	 */
	public static boolean judgeMail(String mailAddress){
		String regex="^[\\w]*[@][\\w]*.com$";
		return judgeMethod(regex, mailAddress);
	}
	/**
	 * 校验小数
	 */
	public static boolean judgeDecimal(String decimal){
		String regex="^(\\d+\\.\\d+)|(\\d+)$";
		return judgeMethod(regex, decimal);
	}
	/**
	 * 获取校验正则方法
	 */
	private static boolean judgeMethod(String regex,String toJudge){
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(toJudge);
		return m.matches();
	}
	public static void main(String[] args) {
//		logger.info("result:"+judgePhoneNumber("15212345678"));
//		logger.info("result:"+judgeMail("w_5@1d.com"));
//		logger.info("result:"+judgeDecimal("0.25a"));
		String url="www.baidu.com?name=ss";
		System.out.println(url.substring(0,url.indexOf("?")));
	}
}
